﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using EazyCMS.Common;
using System.Web.Script.Serialization;

namespace EazyCMS.Web.tools
{
    /// <summary>
    /// GetLanMu 的摘要说明
    /// </summary>
    public class GetLanMu : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string _channel_id = context.Request["selectvalue"];
            int channel_id = Convert.ToInt32(_channel_id);
            BLL.article_category bll = new BLL.article_category();
            DataTable dt = bll.GetList(0, channel_id);
            LanMuStore lanmustore = new LanMuStore();
            lanmustore.Lms = new OneLanMu[dt.Rows.Count];
            int i = 0;
            foreach (DataRow dr in dt.Rows)
            {
                
                string Id = dr["id"].ToString();
                int ClassLayer = int.Parse(dr["class_layer"].ToString());
                string Title = dr["title"].ToString().Trim();
                OneLanMu onelanmu = new OneLanMu();
                if (ClassLayer == 1)
                {
                    onelanmu.BiaoShi = "1";
                    onelanmu.Title = Title;
                    onelanmu.Id = Id;
                   // this.ddlCategoryId.Items.Add(new ListItem(Title, Id));
                }
                else
                {
                    onelanmu.BiaoShi = "2";
                    Title = "├ " + Title;
                    Title = Utils.StringOfChar(ClassLayer - 1, "　") + Title;
                    onelanmu.Title = Title;
                    onelanmu.Id = Id;
                  
                   // this.ddlCategoryId.Items.Add(new ListItem(Title, Id));
                }
                lanmustore.Lms[i] = onelanmu;
                i++;
            }


            context.Response.Write(new JavaScriptSerializer().Serialize(lanmustore));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
    class LanMuStore
    {
        public OneLanMu[] Lms { get; set; }
    
    }
    //栏目实体
    class OneLanMu
    {
        public string BiaoShi { get; set; }
        public string Title { get; set; }
        public string Id { get; set; }
    
    }
   
}